#ifndef QTEST_FOLD_H_
#define QTEST_FOLD_H_

/**
 * @file QTest_Fold.h
 */

#include <QtGui/QApplication>
#include <QtCore/QObject>
#include <QtTest/QtTest>

#include "core/TimeSeries.h"
#include "fold/Folding.h"
#include "widgets/plotting/ScatterPlot.h"
#include <qwt_plot.h>

#include <QtCore/QVector>
#include <vector>

using namespace std;
using namespace spectClean;

class QTest_Fold : public QObject
{
    private:
        Q_OBJECT

    public:
        QTest_Fold() {}
        ~QTest_Fold() {}

    private slots:
        void test()
        {
            TimeSeries t;
            generate_time_series(t);
            scatter(t.size(), &t.time()[0], &t.amp()[0], "time series");

            const unsigned num_bins = 10;
            const double fold_frequency = 10.0;
            const double fold_period = 1.0 / fold_frequency;
            QVector<double> folded_data(t.size(), 0.0);
            Folding::fold_time_series(num_bins, fold_period,
                    t.size(), &t.time()[0], &t.amp()[0],
                    folded_data.data());

//            scatter(t.size(), &t.time()[0], folded_data.constData(), "phase");
        }


    private:

        void generate_time_series(TimeSeries & t)
        {
            typedef SpectrumComponent fc;
            const unsigned num_data = 100;
            std::vector<fc> components;
            components.push_back(fc(5.0, 5.0));
            //components.push_back(fc(1.0, 10.0));

            //t.generateRandom(100, 0.0, 1.0, components);
            t.generateEven(num_data, 0.0, 1.0, components);
        }

        void scatter(const int n, const double * x, const double * y,
                const QString & title = "")
        {
            _s.push_back(new ScatterPlot);
            _s.back()->setSamples(x, y, n);
            _p.push_back(new QwtPlot);
            _p.back()->setMinimumSize(800, 600);
            _p.back()->setVisible(true);
            _s.back()->attach(_p.back());
            _p.back()->setTitle(title);
        }

    private:
        QVector<QwtPlot*> _p;
        QVector<ScatterPlot*> _s;
};


int main(int argc, char ** argv)
{
    QApplication app(argc, argv);
    QTest_Fold test;
    QTest::qExec(&test, argc, argv);
    return app.exec();
}



#endif // QTEST_TIME_SERIES_H_
